<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="../templates/principal.xhtml">

    <ui:define name="content" id="content">
        <h1 class="title ui-widget-header ui-corner-all">Bem Vindo ao Cadastro de D.D.I.</h1>

        <h:form id="frmDdi">
            
            
            <p:dataTable id="tabDdi" widgetVar="wtabDdi" var="codigoDdi" value="#{codigoDdiBean.lazyModel}" 
                         paginator="true" rows="10" lazy="true" 
                         rowStyleClass="#{empty rowIndex or rowIndex mod 2 ne 0 ? 'even-row' : ''}" rowIndexVar="rowIndex"
                         selection="#{codigoDdiBean.selectedCodigoDdi}" selectionMode="single"
                         onRowSelectComplete="codigoDdiDialog.show()" onRowSelectUpdate="display">

                <f:facet name="header">
                    Selecione uma linha e clique para Manutenção
                </f:facet>

                <p:column headerText="D.D.I." sortBy="#{codigoDdi.ddi}" filterBy="#{codigoDdi.ddi}">
                    <h:outputText value="#{codigoDdi.ddi}" />
                </p:column>
                
                <p:column headerText="Descrição" sortBy="#{codigoDdi.descricao}" filterBy="#{codigoDdi.descricao}">
                    <h:outputText value="#{codigoDdi.descricao}" />
                </p:column>

            </p:dataTable>

            <p:dialog id="dialog" header="Detalhes D.D.I." widgetVar="codigoDdiDialog" resizable="true"
                      width="700" showEffect="explode" hideEffect="explode">

                <h:panelGrid id="display" columns="2" style="margin-bottom:50px" cellpadding="5">
                    <h:outputText value="Código D.D.I.:" />
                    <p:inputText id="inDdi" value="#{codigoDdiBean.selectedCodigoDdi.ddi}" 
                                 style="width:100px; font-weight:bold" rendered="true"
                                 onkeyup="javascript:maskIt(this,event,'#####',true)"/>

                    <h:outputText value="Descrição:" />
                    <p:inputText id="indscTipo" value="#{codigoDdiBean.selectedCodigoDdi.descricao}" required="true" style="width:500px; font-weight:bold" />
                </h:panelGrid>
                <br />
                <p:commandButton value="Inserir" update="messages,tabDdi,display"
                                 actionListener="#{codigoDdiBean.inserir}" oncomplete="codigoDdiDialog.hide()" />
                <p:commandButton value="Alterar" update="messages,tabDdi,display"
                                 actionListener="#{codigoDdiBean.alterar}" oncomplete="codigoDdiDialog.hide()" />
                <p:commandButton value="Excluir" onclick="confirmation.show()" type="button" />
            </p:dialog>

            <p:confirmDialog message="Confirma a Exclusão desse D.D.I.?"
                             showEffect="bounce" hideEffect="explode"
                             header="Exclusão do D.D.I." severity="alert" widgetVar="confirmation">

                <p:commandButton value="Sim" update="messages,tabDdi,display" oncomplete="confirmation.hide(),codigoDdiDialog.hide()"
                                 actionListener="#{codigoDdiBean.excluir}" />
                <p:commandButton value="Não" onclick="confirmation.hide()" type="button" />

            </p:confirmDialog>
            
        </h:form>
    </ui:define>
</ui:composition>